authenticate.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A authenticate.js ➔ ... ➔ ??? 0 9 2
1
const {User} = require('./../models/user');
2
3
let authenticate = (req, res, next) => {
4
    let token = req.header('x-auth');
5
    
6
    User.findByToken(token).then((user) => {
7
        if(!user) {
8
            return Promise.reject();
9
        }
10
        // modify the req object to be used in the route
11
        req.user = user;
12
        req.token = token;
13
        next();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
14
    }).catch((err) => {
15
        res.status(401).send({
16
            err,
17
            status : 401
18
        });
19
    });    
20
}
21
22
module.exports = {authenticate};